//
//  ImageIOSupportImageFormats.m
//  iOSStudy
//
//  Created by Evan Xie on 8/24/15.
//  Copyright (c) 2015 Family Wings. All rights reserved.
//

#import <ImageIO/ImageIO.h>
#import "ImageIOSupportImageFormats.h"


@interface ImageIOSupportImageFormats ()

@property (nonatomic, strong) NSArray *dataSourceArray;

@end

@implementation ImageIOSupportImageFormats

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    CFArrayRef srcFormats = CGImageSourceCopyTypeIdentifiers();
    CFArrayRef destFormats = CGImageDestinationCopyTypeIdentifiers();
    NSArray *supportedSourceFormats = (__bridge NSArray*)srcFormats;
    NSArray *supportedDestinationFormats = (__bridge NSArray *)destFormats;
    
    self.dataSourceArray = @[
        @{kSectionNameKey: @"Supported Source UTIs", kItemNamesKey: supportedSourceFormats},
        @{kSectionNameKey: @"Supported Destination UTIs", kItemNamesKey: supportedDestinationFormats}
    ];
    
    CFRelease(srcFormats);
    CFRelease(destFormats);
}


#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSourceArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataSourceArray[section][kItemNamesKey] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ImageFormatsCell" forIndexPath:indexPath];
    cell.textLabel.text = self.dataSourceArray[indexPath.section][kItemNamesKey][indexPath.row];
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return self.dataSourceArray[section][kSectionNameKey];
}

@end
